<?php
/*
 * Copyright 2008 by Oliver Radwan, Maxwell Palmer, Nolan McNair,
 * Taylor Talmage, and Allen Tucker.  This program is part of RMH Homebase.
 * RMH Homebase is free software.  It comes with absolutely no warranty.
 * You can redistribute it and/or modify it under the terms of the GNU
 * General Public License as published by the Free Software Foundation
 * (see <http://www.gnu.org/licenses/ for more information).
*/

 include_once('RMHdate.php');
/*
 * Week is an array of dates
 * Weeks start on Mondays
 * For any date givento either constructor function,
 * the script will find the Monday of that week, and generate dates from there
 * @author Maxwell Palmer
 * @version 4/30/08, modified 9/12/08
 */
/*
function new_week_from_db($dates, $weekday_group, $weekend_group, $fam_group, $status) {
	$w=new Week($dates, $weekday_group, $weekend_group, $fam_group, $status);
//	$w->db_week($dates, $weekday_group, $weekend_group, $fam_group, $status);
	return $w;
}
*/
class Week {
	private $id;	   // the first day of the week, mm-dd-yy
 	private $dates;    // array of 7 RMHdates, beginning Monday
	private $name;     // the name of the week (ie March 7, 2008 - March 14, 2008)
	private $weekday_group;	// 1 or 2
	private $weekend_group;	// 1-5
	private $family_room_group; // 1 or 2
	private $status;	// status of the week, "unpublished", "published" or "archived"
	private $end_of_week_timestamp;	// the mktime timestamp of the end of the week
	private $weekArray;
   
 	/**
 	 * Creates a new calendar.
 	 */
 	function __construct($dates,$weekday_group,$weekend_group,$fam_group,$status) {
 		//$this->dates=$dates;
 		//mktime(0,0,0,$mm,$dd,$yy);
 		$this->dates = date("m-d-y",$this-> end_of_week_timestamp);
 		for($i=0; $i<=6; $i++)
 			$this->weekArray[i]= date("l",$date);//fill array using first parameter with name of the days
		$this->weekday_group=$weekday_group;
		$this->weekend_group=$weekend_group;
		$this->family_room_group = $fam_group;
		$this->status=$status;
		$this->id=$this->dates[0]->get_id();
		$this->name=$this->dates[0]->get_name()." to ".$this->dates[6]->get_name();
		$this->end_of_week_timestamp=$this->dates[6]->get_end_time();
 	}
 	/*
 	function generate_week($m,$d,$y,$wkday,$wkend,$fam) {
 		$timestamp = mktime(0,0,0,$m,$d,$y);
 		$dow = date("N",$timestamp);
		for($i=1;$i<=7;++$i) {
			// currently generated new dates and empty shifts.  in future, will shift from master schedule
			$this->dates[]=generate_new_date(date("m",mktime(0, 0, 0, $m, $d-$dow+$i, $y)),
			date("d",mktime(0, 0, 0, $m, $d-$dow+$i, $y)),
			date("Y",mktime(0, 0, 0, $m, $d-$dow+$i, $y)));
		}
		$this->id=$this->dates[0]->get_id();
		$this->name=$this->dates[0]->get_name()." to ".$this->dates[6]->get_name();
		$this->status="unpublished";
		$this->weekday_group=$wkday;
		$this->weekend_group=$wkend;
		$this->family_room_group = $fam;
		$this->end_of_week_timestamp=$this->dates[6]->get_end_time();
 	}

	function db_week($dates,$weekday_group,$weekend_group,$fam_group,$status) {
		$this->dates=$dates;
		$this->weekday_group=$weekday_group;
		$this->weekend_group=$weekend_group;
		$this->family_room_group = $fam_group;
		$this->status=$status;
		$this->id=$this->dates[0]->get_id();
		$this->name=$this->dates[0]->get_name()." to ".$this->dates[6]->get_name();
		$this->end_of_week_timestamp=$this->dates[6]->get_end_time();
	}
	*/
	function get_name() {
		return $this->name;
	}
	function get_id() {
		return $this->id;
	}
	function get_dates() {
		return $this->dates;
	}
	function get_status() {
		return $this->status;
	}
	function get_end() {
		return $this->end_of_week_timestamp;
	}
	function get_weekday_group() {
		return $this->weekday_group;
	}
	function get_weekend_group() {
		return $this->weekend_group;
	}
	function get_family_room_group() {
		return $this->family_room_group;
	}
	function set_status($s) {
		if($s=="unpublished" || $s=="published" || $s=="archived") {
			$this->status=$s;
		}
		else
			return false;
	}
 }
 ?>
